﻿<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" MasterPageFile="~/Views/Shared/Iframe.Master" %>

<asp:Content runat="server" ContentPlaceHolderID="cphJScripts">
    <script type="text/javascript">
        $(document).ready(function () {
            <% if(!this.ViewData.ModelState.IsValid){ %>
                resize();
            <% } %>

            $(".blockButton .green").click(function () {
                $("ul.validation-summary-errors").empty();
                resize();
                $(this).addClass("loading");
                if (!$("#contentPage form").valid()) {
                    resize();
                    $(this).removeClass("loading");
                } else {
                    $("form")[0].submit();
                }
            })

            $(".blockButton .blue").click(function () {
                validator.resetForm();
                $('form')[0].reset();
                resize();
            })

            var container = $('#error');
            var validator = $("form").validate({
                errorContainer: container,
                errorLabelContainer: $("ul", container),
                wrapper: 'li',
                onfocusin: false,
                onfocusout: false,
                onkeyup:false,
                unhighlight: function (element, errorClass) {
                    resize();
                },
                rules: {
                    Title: {
                        required: true
                    },
                    Description: {
                        maxlength: 250,
                        required: true
                    },
                    URL: {
                        url: true,
                        required: true
                    },
                    recaptcha_response_field: {
                        required: true
                    }
                },

                messages: {
                    Title: "<%= ScoutNET.Resources.Liens_Create_Title_Error_Required %>",
                    Description:
                    {
                        maxlength: "<%= ScoutNET.Resources.Liens_Create_Description_Error_Maxlength %>",
                        required: "<%= ScoutNET.Resources.Liens_Create_Description_Error_Required %>"
                    },
                    URL:
                    {
                        url: "<%= ScoutNET.Resources.Liens_Create_Url_Error_Url %>",
                        required: "<%= ScoutNET.Resources.Liens_Create_Url_Error_Required %>"
                    },
                    recaptcha_response_field:
                    {
                        required: "<%= ScoutNET.Resources.Contact_Index_Error_Captcha %>"
                    }
                }
            });
        });
    </script>
</asp:Content>

<asp:Content runat="server" ContentPlaceHolderID="cphMainContent">
<div id="contentPage">
    <div id="error" class="<%= (!this.ViewData.ModelState.IsValid) ? string.Empty : "hide"%>">
        <span class="validation-summary-errors"><%= ScoutNET.Resources.Master_Form_ErrorMessage %></span>
        <ul class="validation-summary-errors">
            <%  foreach (var modelError in this.ViewData.ModelState.Where(p => p.Value.Errors.Count > 0).ToList()) {
                foreach (var error in modelError.Value.Errors) { %>
                    <li><%= error.ErrorMessage %></li>
            <% }
            } %>
        </ul>
    </div>

    <% using (Html.BeginForm()) {%>
        <p>
            <label for="Title"><%= ScoutNET.Resources.Liens_Create_Title%>:</label>
            <%= Html.TextBox("Title", null, new { @class = "small", maxlength = "50" })%>
        </p>
        <p>
            <label for="Description"><%= ScoutNET.Resources.Liens_Create_Description %>:</label>
            <%= Html.TextArea("Description", null, new { @class = "smallTextArea", maxlength = "250" })%>
        </p>
        <p>
            <label for="URL"><%= ScoutNET.Resources.Liens_Create_Url %>:</label>
            <%= Html.TextBox("URL", null, new { @class = "small", maxlength = "250" })%>
        </p>

        <% if (!User.Identity.IsAuthenticated){ %>
        <p>
            <label for="recaptcha_response_field"><%= ScoutNET.Resources.Contact_Index_Captcha%> : </label>
            <%= Html.GenerateCaptcha(HttpContext.Current)%>
        </p>
        <% } %>

        <%= Html.AntiForgeryToken() %>
        <div class="clr"></div>
        <div class="blockButton">	
	        <a class="mediumBtn green awesome" href="javascript:void(0);" title="<%= ScoutNET.Resources.Master_Button_Submit %>"><%= ScoutNET.Resources.Master_Button_Submit%></a>
	        <a class="mediumBtn blue awesome" href="javascript:void(0)" title="<%= ScoutNET.Resources.Master_Button_Reset %>"><%= ScoutNET.Resources.Master_Button_Reset%></a>
        </div>
    <% } %>
</div>
</asp:Content>